<?php defined('SYSPATH') or die('No direct script access.');

// Все, что не относится к другим контроллерам, пишем сюда.
class Controller_Admin_Login extends Controller_Admin_Base
{
	// Настройки
	protected $need_auth = false;	// Не нужна авторизация
	
	public function action_login()
	{
		$message = null;
             
        if (HTTP_Request::POST == $this->request->method())
        {
            $remember = array_key_exists('remember', $this->request->post()) ? (bool)$this->request->post('remember') : false;
            $user = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), $remember);
			
            if($user && Auth::instance()->logged_in('admin'))
                Request::current()->redirect('admin');
            else
                $message = 'Неверный логин или пароль!';
        }
		
		$view = new View('admin/login_tpl');
		$view->message = $message;
		
		$this->response->body($view);
	}
	
	public function action_logout()
	{
		if(Auth::instance()->logged_in())
			Auth::instance()->logout();
		
		$this->user = null;
		Request::current()->redirect('admin/login');
	}

} // End Admin_Login
